﻿using ProjectFootball.MVC.Models.EntityFramework.Entities;
using System;

namespace ProjectFootball.MVC.Models
{
    public class LeagueTableItemViewModel : IComparable<LeagueTableItemViewModel>
    {
        public TeamVersion TeamVersion { get; set; }
        public int HomeWins { get; set; }
        public int HomeDraws { get; set; }
        public int HomeLosses { get; set; }
        public int AwayWins { get; set; }
        public int AwayDraws { get; set; }
        public int AwayLosses { get; set; }
        public int HomeScored { get; set; }
        public int HomeConceded { get; set; }
        public int AwayScored { get; set; }
        public int AwayConceded { get; set; }

        public int Wins
        {
            get { return HomeWins + AwayWins; }
        }

        public int Draws
        {
            get { return HomeDraws + AwayDraws; }
        }

        public int Losses
        {
            get { return HomeLosses + AwayLosses; }
        }

        public int Played
        {
            get { return Wins + Draws + Losses; }
        }

        public int Scored
        {
            get { return HomeScored + AwayScored; }
        }

        public int Conceded
        {
            get { return HomeConceded + AwayConceded; }
        }

        public int GoalDifference
        {
            get { return Scored - Conceded; }
        }

        public int Points
        {
            get { return (Wins * 3) + Draws; }
        }

        public int CompareTo(LeagueTableItemViewModel other)
        {
            if (Points != other.Points)
                return -Points.CompareTo(other.Points);

            if (GoalDifference != other.GoalDifference)
                return -GoalDifference.CompareTo(other.GoalDifference);

            if (Scored != other.Scored)
                return -Scored.CompareTo(other.Scored);

            return TeamVersion.TeamName.CompareTo(other.TeamVersion.TeamName);
        }
    }
}